events %>% 
  filter(state == "MI") %>% 
    group_by(cand_lastname) %>% 
    count(cand_lastname)
## # A tibble: 20 x 2
## # Groups:   cand_lastname [20]
##    cand_lastname     n
##    <chr>         <int>
##  1 Bennet            1
##  2 Biden             2
##  3 Booker            3
##  4 Bullock           1
##  5 Buttigieg         1
##  6 Castro            3
##  7 de Blasio         1
##  8 Delaney           2
##  9 Gabbard           1
## 10 Gillibrand        3
## 11 Harris            4
## 12 Hickenlooper      1
## 13 Inslee            2
## 14 Klobuchar         4
## 15 O'Rourke          3
## 16 Ryan              1
## 17 Sanders           3
## 18 Warren            3
## 19 Williamson        1
## 20 Yang              2
#Data Visualisation
fig <- plot_ly(data=events, labels = ~cand_lastname, values = ~n)

fig <- fig %>% add_pie(hole = 0.6) #would make a pie chart, to make a donut chart add the hole

fig <- fig %>% layout(
                  title = "Events in Michigan by Candidate",  showlegend = F,
                  xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
                  yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

fig 

```

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.